const assert = require("assert");
const Service = require("../src/service.js");

describe("service.js", () => {
  before(() => {
    console.log("init");
    Service.init("shenga.co", true);
  });

  describe("get()", () => {
    it("ok", async () => {
      const result = await Service.get("supplier", "/");
      console.log(result);
      assert(result.code == 1004);
    });

    it("async", async () => {
      const result = await Service.get("supplier", "/", null, true, 2);
      console.log(result);
    });

    it("fail", async () => {
      const result = await Service.get("a", "/");
      console.log(result);
      assert(result.code == 1004);
    });
  });

  describe("post()", () => {
    it("ok", async () => {
      const result = await Service.post("supplier", "/");
      console.log(result);
      assert(result.code == 1004);
    });

    it("async", async () => {
      const result = await Service.get("supplier", "/", null, true, 2);
      console.log(result);
    });

    it("json format", async () => {
      const result = await Service.post("post", "/", { a: 1 }, false, 0, false);
      console.log(result);
      assert(result.success);
    });
  });
});
